<?php use Backend\Controller\Plugin\AuthorizationPlugin; ?>

<?php echo $this->partial('sejour/sejourNavPartial', array (
    'sejourId' => $this->id
  ));
?>

<div ng-app="sejourModule">
	<div class="table-responsive" ng-controller="DisponibiliteSejourController">
		<div class="row">

			<input type="hidden" id="id" value="<?php echo $this->id;?>">
			<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{alert.msg}}</alert>

			<div class="panel panel-primary">
				<div class="panel-heading">Ajouter une nouvelle disponibilit&#233; au s&#233;jour</div>
				<div class="panel-body">
					<form id="formDisponibilite"  ng-submit="post(formDisponibilite.$valid)" name="formDisponibilite" class="formDisponibilite"  novalidate>
						
						<div class="row">
							<div class="col-lg-6">
								<div class="row">
									<div class="col-lg-6">
										<div class="form-group">
											<label for="dispoDateDebut">Date de d&#233;but</label>
											
											<p class="input-group">
												<input id="dispoDateDebut" name="dispoDateDebut" datepicker-popup="dd-MMMM-yyyy" datepicker-options="{'starting-day': 1}" type="text" class="form-control" ng-class="{ 'input-block' : submitted }" ng-model="dispo.dateDebut" is-open="openedDateDebut" required close-text="Close" />
												<span class="input-group-btn">
								            	    <button class="btn btn-default" ng-click="openDateDebut($event)"><i class="fa fa-calendar"></i></button>
								              	</span>
											</p>

											<p ng-show="formDisponibilite.dispoDateDebut.$invalid && submitted == true" class="help-block">Veuillez sélectionner une date de début.</p>

										</div>
									</div>
									<div class="col-lg-6">
										<div class="form-group">
											<label for="dispoDateFin">Date de fin</label>
											<p class="input-group">
												<input id="dispoDateFin" name="dispoDateFin" datepicker-popup="dd-MMMM-yyyy" datepicker-options="{'starting-day': 1}" type="text" class="form-control" ng-model="dispo.dateFin" is-open="openedDateFin" ng-class="{ 'input-block' : submitted }" required close-text="Close" />
												<span class="input-group-btn">
								            	    <button class="btn btn-default" ng-click="openDateFin($event)"><i class="fa fa-calendar"></i></button>
								              	</span>
											</p>

											<p ng-show="formDisponibilite.dispoDateFin.$invalid && submitted == true" class="help-block">Veuillez sélectionner une date de fin.</p>

										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-lg-6">
								<div class="row">
									<div class="col-lg-6">
										<div class="form-group">
											<label for="dispoNbDispo">Disponibilité</label>
											<input id="dispoNbDispo" name="dispoNbDispo" ng-model="dispo.nbDispo" type="number" placeholder="Nombre de place disponible" class="form-control" min="0" max="999">
										</div>

									</div>
									<div class="col-lg-6">
										<div class="form-group">
											<label for="dispoPrix">Prix</label>
											<input id="dispoPrix" name="dispoPrix" ng-model="dispo.prix" type="number" placeholder="Notez le prix" class="form-control" ng-class="{ 'input-block' : submitted }" required>
										</div>

										<p ng-show="formDisponibilite.dispoPrix.$invalid && submitted == true" class="help-block">Veuillez saisir un prix.</p>

									</div>
								</div>
							</div>
							<div class="col-lg-6">
								<div class="row">
									<div class="col-lg-6">
										<div class="form-group">
											<label for="dispoEtat">Etat</label>

											<select id="sejourThemeParcours" class="form-control" ng-model="dispo.etat" ng-options="etat.libelleEtatDispo as etat.libelleEtatDispo for etat in etats">
							    				<option style="display:none" value="">Saisissez l'&#233;tat</option>
											</select>

										</div>
									</div>
									<div class="col-lg-6">
										<div class="row">
											<div class="col-lg-6">
												<div class="form-group">
													<label>&nbsp;</label>
													<?php if( AuthorizationPlugin::isAllowed2($this->layout()->loadIdentity, "Sejour", "edit") ) { ?>
														<button type="submit" class="form-control btn btn-primary">{{dispo.idDate == null ? addButton : updateButton}}</button>
													<?php } ?>
												</div>
											</div>
											<div class="col-lg-6">
												<div class="form-group">
													<label>&nbsp;</label>
													<button ng-click="cancel()" ng-disabled="!formDisponibilite.$dirty" type="button" class="form-control btn btn-default">Annuler</button>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>	
		</div>

		<div class="row">
			<div class="panel panel-default">
				<div class="panel-heading">Disponibilit&#233;es du s&#233;jour</div>
				<table class="table table-bordered table-hover table-striped tablesorter">
			    	<thead>
			        	<tr>
							<th class="col-sm-2">Date de d&#233;but <i class="fa fa-sort"></i></th>
							<th class="col-sm-2">Date de fin <i class="fa fa-sort"></i></th>
							<th class="col-sm-1">Prix <i class="fa fa-sort"></i></th>
							<th class="col-sm-4">Disponibilités restantes <i class="fa fa-sort"></i></th>
							<th class="col-sm-2">Etat <i class="fa fa-sort"></i></th>
							<th class="col-sm-1">&nbsp;</th>
						</tr>
					</thead>
					<tbody>
						<tr ng-repeat="disponibilite in disponibilites">
								<td>{{disponibilite.dateDebut}}</td>
								<td>{{disponibilite.dateFin}}</td>
								<td>{{disponibilite.prix}}</td>
								<td>{{disponibilite.nbDispo}}</td>
								<td>{{disponibilite.etat}}</td>
								<td>
									<?php if( AuthorizationPlugin::isAllowed2($this->layout()->loadIdentity, "Sejour", "edit") ) { ?>
											<div class="btn-group btn-actions-bo">
												<button type="button" class="btn btn-primary">Actions</button>
											  	<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
											    	<span class="caret"></span>
											    	<span class="sr-only">Toggle Dropdown</span>
											  	</button>
											  	<ul class="dropdown-menu" role="menu">
									    			<li><a href="#" ng-click="editerDisponibilite(disponibilite)">Editer</a></li>
									    			<li><a href="#" ng-click="deleteDisponibilite(disponibilite)">Supprimer</a></li>
											  	</ul>
											</div>
									<?php } ?>
								</td>
							</tr>
					</tbody>
				</table>
			</div>

			
		</div>
	</div>
</div>	
